/*
 * WordPicker.cpp

 *
 *  Created on: 28/12/2012
 *
 */

#include "WordPicker.h"

void WordPicker::loadWords (map <string, string> *mapa)
{
		ifstream inFile;
		inFile.open("data/words.txt");
		while (!inFile.eof())
		{
			getline (inFile, linha, ':');
			palavra = linha;
			if (getline (inFile, linha, '\n'))
			{
				dica = linha;
			}
			mapa->insert (pair <string, string> (palavra, dica));
		}
		inFile.close();
}

GameWord WordPicker::pickWord()
{
		GameWord gameWord;
		map <string,string> wordsMap;
		loadWords(&wordsMap);
		srand((unsigned)time(0));
		map <string, string>::iterator finder;

    	finder = wordsMap.begin();
    	advance(finder, (rand() % wordsMap.size()));
    	gameWord.word = finder->first;
    	gameWord.tip = finder->second;
    	return gameWord;

}



